package com.dl7.mvp.local.table;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.dl7.downloaderlib.model.DownloadStatus;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;

/**
 * 视频实体
 */
@Entity
public class VideoInfo implements Parcelable {
    @Id
    private String url;
    private int play_count;
    private String name;
    private String image;
    private int albumId;

    /**
     * 文件大小，字节
     */
    private long totalSize;
    /**
     * 已加载大小
     */
    private long loadedSize;
    /**
     * 下载状态
     */
    private int downloadStatus = DownloadStatus.NORMAL;
    /**
     * 下载速度
     */
    private long downloadSpeed;
    /**
     * 是否收藏
     */
    private boolean isCollect;


    protected VideoInfo(Parcel in) {
        name = in.readString();
        image = in.readString();
        url = in.readString();
        play_count = in.readInt();
        albumId = in.readInt();

        totalSize = in.readLong();
        loadedSize = in.readLong();
        downloadStatus = in.readInt();
        downloadSpeed = in.readLong();
        isCollect = in.readByte() != 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(name);
        parcel.writeString(image);
        parcel.writeString(url);
        parcel.writeInt(play_count);
        parcel.writeInt(albumId);
        parcel.writeLong(totalSize);
        parcel.writeLong(loadedSize);
        parcel.writeInt(downloadStatus);
        parcel.writeLong(downloadSpeed);
        parcel.writeByte((byte) (isCollect ? 1 : 0));
    }

    public static final Creator<VideoInfo> CREATOR = new Creator<VideoInfo>() {
        @Override
        public VideoInfo createFromParcel(Parcel in) {
            return new VideoInfo(in);
        }

        @Override
        public VideoInfo[] newArray(int size) {
            return new VideoInfo[size];
        }
    };

    public boolean getIsCollect() {
        return this.isCollect;
    }

    public void setIsCollect(boolean isCollect) {
        this.isCollect = isCollect;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getImage() {
        return image;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUrl() {
        return url;
    }

    public void setPlay_count(int play_count) {
        this.play_count = play_count;
    }

    public int setAlbumId() {
        return albumId;
    }

    public int getAlbumId() {
        return albumId;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public long getLoadedSize() {
        return loadedSize;
    }

    public void setLoadedSize(long loadedSize) {
        this.loadedSize = loadedSize;
    }

    public int getDownloadStatus() {
        return downloadStatus;
    }

    public void setDownloadStatus(int downloadStatus) {
        this.downloadStatus = downloadStatus;
    }

    public long getDownloadSpeed() {
        return downloadSpeed;
    }

    public void setDownloadSpeed(long downloadSpeed) {
        this.downloadSpeed = downloadSpeed;
    }

    public boolean isCollect() {
        return isCollect;
    }

    public void setCollect(boolean collect) {
        isCollect = collect;
    }

    public void setAlbumId(int albumId) {
        this.albumId = albumId;
    }

    public int getPlay_count() {
        return this.play_count;
    }

    public VideoInfo() {
    }

    /**
     * 通过推荐的Video构建
     *
     * @param videoBean
     */
    public VideoInfo(VideoList.DataBean.VideoBean videoBean) {
        url = videoBean.getResource();
        name = videoBean.getName();
        image = videoBean.getImage();
        play_count = videoBean.getPlayCount();
        albumId = videoBean.getAlbumId();
    }


    /**
     * 通过专辑详情构建
     *
     * @param data
     */
    public VideoInfo(AlbumsVideoList.DataBean data) {
        url = data.getResource();
        name = data.getName();
        image = data.getImage();
        play_count = data.getPlayCount();
        albumId = data.getAlbumId();
    }

    /**
     * 通过推荐专辑构建。
     * @param data
     */
    public VideoInfo(RecommendAlbumsListBean.DataBean data) {
        name = data.getName();
        image = data.getIconUrl();
        play_count = data.getPlayCount();
        albumId = data.getId();
    }


    @Generated(hash = 952408765)
    public VideoInfo(String url, int play_count, String name, String image,
                     int albumId, long totalSize, long loadedSize, int downloadStatus,
                     long downloadSpeed, boolean isCollect) {
        this.url = url;
        this.play_count = play_count;
        this.name = name;
        this.image = image;
        this.albumId = albumId;
        this.totalSize = totalSize;
        this.loadedSize = loadedSize;
        this.downloadStatus = downloadStatus;
        this.downloadSpeed = downloadSpeed;
        this.isCollect = isCollect;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj != null && obj instanceof VideoInfo) {
            return TextUtils.equals(getUrl(), ((VideoInfo) obj).getUrl());
        }
        return false;
    }
}
